//该文件用于创建Vuex中最为核心的store
import Vue from 'vue'
//引入Vuex
import Vuex from 'vuex'
//应用Vuex插件
Vue.use(Vuex)


export default new Vuex.Store({
    state: {
        token: window.localStorage.getItem('token'),
        user:window.localStorage.getItem('user')?JSON.parse(window.localStorage.getItem('user')):null
    },
    mutations: {
        changeToken(state,token) {
            state.token = token
            localStorage.setItem('token', token)
        },
        updateUser(state,user) {
            state.user = user
            localStorage.setItem('user', JSON.stringify(user))
        }
    },
    actions: {
        changeToken(context,  token ) {
            context.commit('changeToken', token)
        },
        updateUser(context,  user ) {
            context.commit('updateUser', user)
        },
    }
})

